package exercises.leetcode;

import exercises.newcoder.util.ListNode;

/**
 * <a href="https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/">
 * 83. 删除排序链表中的重复元素</a>
 *
 * <p><span color="#87CEEB">描述:</span>
 * 学习计划广场
 *
 * @author or2
 * @date 2021年10月02日 时间: 19:29
 */
public class No203 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode auxiliary = new ListNode(0, head);
        for (ListNode pointer = auxiliary; pointer.next != null; pointer = pointer.next)
            while (pointer.next.val == val) {
                pointer.next = pointer.next.next;
                if (pointer.next == null)
                    return auxiliary.next;
            }
        return auxiliary.next;
    }
}
